<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:pe="http://primefaces.org/ui/extensions">
    <h:head>
        <title>#{bundle.collateral}</title>
        <link href="./resources/css/default.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <ui:composition>
        <h:form >
            <script type="text/javascript">  
                function handleSaveRequestCollateral(xhr, status, args) {  
                    if(args.validationFailed || !args.success) {  
                        jQuery('#dialog').effect("shake", { times:3 }, 100);  
                    } else {  
                        dlgCollateral.hide();  
                    }  
                }
                
                function handleDeleteRequestCollateral(xhr, status, args) {  
                    if(args.validationFailed || !args.success) {  
                        jQuery('#dialog').effect("shake", { times:3 }, 100);  
                    } else {  
                        dlgDelcoral.hide();  
                    }  
                }
                
                function componenKeyPress(e) {
                    var code = (e.keyCode ? e.keyCode : e.which);
                    if(code==13) {
                        submitCollateral.jq.click();
                        //jQuery('#submitCollateral').focus();  
                        e.preventDefault();
                    }
                }
                
            </script>  

            <p:toolbar>
                <p:toolbarGroup align="left">
                    <p:commandButton value="#{bundle.btnNew}"
                                     icon="ui-icon-document" rendered="#{menuBean.cekButtonAccess(362,'INS;')}"
                                     action="#{collateralBean.newData()}"  
                                     oncomplete="dlgCollateral.show()"
                                     process="@this" update=":#{utilityBean.findClientId('displayCollateral')}"> 
                        <pe:resetEditableValues for="displayCollateral"/>
                    </p:commandButton>

                    <p:commandButton value="#{bundle.btnOpen}" oncomplete="dlgCollateral.show()" 
									rendered="#{menuBean.cekButtonAccess(362,'OPN;')}"
                                     icon="ui-icon-disk" actionListener="#{collateralBean.openData()}"
                                     update=":#{utilityBean.findClientId('displayCollateral')}" > 
                    </p:commandButton>

                    <p:commandButton value="#{bundle.btnDelete}" icon="ui-icon-trash" onclick="dlgDelcoral.show()" 
                                     rendered="#{menuBean.cekButtonAccess(362,'DEL;')}" />

                    <!--p:commandButton type="push" value="#{bundle.btnPrint}" icon="ui-icon-print"/ -->
                </p:toolbarGroup>
            </p:toolbar>
            <br />
            <p:dataTable id="dtCollaterals" var="collateral" value="#{collateralBean.collaterals}"
                         resizableColumns="true" rowIndexVar="noUrut"  selection="#{collateralBean.selectedData}" selectionMode="single" 
                         rowKey="#{collateral.collateralId}" >
                 <p:column style="width: 10px">
                    <f:facet name="header">No.</f:facet>
                    <h:outputText value="#{noUrut+1}" />
                 </p:column>
                <p:column style="width:200px">
                    <f:facet name="header">#{bundle.globalName}</f:facet>
                    <h:outputText value="#{collateral.collateralName}" />
                </p:column>
                <p:column style="width:auto" rendered="false">
                    <f:facet name="header">ID</f:facet>
                    <h:outputText value="#{collateral.collateralId}" />
                </p:column>
            </p:dataTable>
            
            <p:confirmDialog message="#{bundle.confirmDelete}" appendToBody="true" 
                             header="#{bundle.confirmDeleteHeader}" severity="alert" widgetVar="dlgDelcoral">
                <h:panelGrid cellspacing="0" cellpadding="0" styleClass="pComBtnD">
                    <f:facet name="footer">
                        <p:commandButton value="#{bundle.btnYes}" update="dtCollaterals" process="@this"
                                         oncomplete="handleDeleteRequestCollateral(xhr, status, args)"  
                                         actionListener="#{collateralBean.delete()}" />  
                        <p:commandButton value="#{bundle.btnCancel}" onclick="dlgDelcoral.hide()" type="button" />  
                    </f:facet>
                </h:panelGrid>  
            </p:confirmDialog> 
        </h:form>
            <p:dialog header="#{bundle.collateral}" widgetVar="dlgCollateral" closable="true" modal="true" appendToBody="true">
                <p:ajax immediate="true" event="close" listener="#{collateralBean.handleClose}"/>
                <h:form>
                <h:panelGrid id="displayCollateral" columns="3" styleClass="addELIT">
                    <h:outputLabel style="padding: 0 15px 0 0;" styleClass="addL" value= "#{bundle.globalName} :" />
                    <h:panelGrid columns="2" cellpadding="0" cellspacing="0" rendered="#{collateralBean.unsaveData!=null}">
                        <p:inputText value="#{collateralBean.unsaveData.collateralName}" 
                                 label="#{bundle.globalName}" style="width: 150px;"
                                 required="true" onkeydown="componenKeyPress(event)" id="coralName1" >
                        <p:ajax update="msgcoralName1" process="@this"/>
                        </p:inputText>  
                        <p:message id="msgcoralName1" for="coralName1" display="icon" />
                    </h:panelGrid>
                </h:panelGrid>

                <h:panelGrid cellpadding="0" styleClass="pComBtnSTDR">
                    <f:facet name="footer">  
                        <p:commandButton value="#{bundle.btnSave}" icon="ui-icon-disk" actionListener="#{collateralBean.save()}"  rendered="#{menuBean.cekButtonAccess(362,'UPD;')}"
                                         update=":#{utilityBean.findClientId('dtCollaterals')}" widgetVar="submitCollateral"                 
                                         oncomplete="handleSaveRequestCollateral(xhr, status, args)"/>  
                        <p:commandButton value="#{bundle.btnClose}" icon="ui-icon-document" immediate="true"
                                         oncomplete="dlgCollateral.hide()" update="displayCollateral" process="@this">
                            <pe:resetEditableValues for="displayCollateral"/>  
                        </p:commandButton>
                            
                    </f:facet>
                </h:panelGrid>
                    </h:form>
            </p:dialog>
        
        </ui:composition>
    </h:body>
</html>